package cn.czxy.service.person;

import cn.czxy.dao.person.PersonDao;
import cn.czxy.domain.Person;
import cn.czxy.domain.User;

import java.util.List;

/**
 * @author lixinghua@itcast.cn
 * @version 1.0
 * @date 2019/4/13
 */
public class PersonService {
    /**和xml数据交互对象*/
    private PersonDao dao = new PersonDao();

    /**
     * 添加用户个人信息
     * @param bean person对象
     */
    public void addPerson(Person bean) {
        List<Person> plist = dao.searchAll();
        if(plist!=null){
            if(plist.contains(bean)){
                plist.remove(bean);
                plist.add(bean);
                dao.writerSave(plist);
                return;
            }
        }
        dao.addPerson(bean);
    }

    /**
     * 查询用户person对象
     * @param bean 用户登录对象
     * @return person对象
     */
    public Person searchByUser(User bean) {
        List<Person> plist =  dao.searchAll();
        if(plist!=null){
            for (Person p : plist) {
                if(p.getUserName().equals(bean.getUserName())){
                    return p;
                }
            }
        }
        return null;
    }
}
